/**
 * IMemoryManager.java
 * Copyright (C) 2011 Yuanyan<yuanyan.cao@gmail.com>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * For information on how to redistribute this software under
 * the terms of a license other than GNU General Public License
 * contact yuanyan.cao@gmail.com
 */
package edu.rabbit.kernel.memory;

import edu.rabbit.kernel.MemoryBufferType;

/**
 * Default implementation of Rabbit's memory manager. It allows allocate memory
 * chunk {@link IMemoryBuffer}.
 * 
 * @author Yuanyan<yanyan.cao@gmail.com>
 * 
 * 
 */
public interface IMemoryManager {

    int BYTE_SIZE = 1;
    int SHORT_SIZE = 2;
    int INT_SIZE = 4;
    int LONG_SIZE = 8;

    /**
     * Get buffers implementation type which is used by default.
     * 
     * @return
     */
    MemoryBufferType getDefaultBufferType();

    /**
     * Get buffers implementation which is used by default.
     * 
     * @param bufferType
     */
    void setDefaultBufferType(MemoryBufferType bufferType);

    /**
     * Allocates memory chunk {@link IMemoryBuffer} using default buffer
     * type.
     * 
     * @param size
     *            size of buffer in bytes
     * @return allocated buffer
     */
    IMemoryBuffer allocate(int size);

    /**
     * @param size
     * @param bufferType
     * @return
     */
    IMemoryBuffer allocate(int size, MemoryBufferType bufferType);

    /**
     * Allocates memory chunk {@link IMemoryBuffer} using default buffer
     * type.
     * 
     * @param size
     *            size of buffer in bytes
     * @return allocated buffer
     */
    IMemoryPointer allocatePtr(int size);

    /**
     * @param size
     * @param bufferType
     * @return
     */
    IMemoryPointer allocatePtr(int size, MemoryBufferType bufferType);
    
    /**
     * Fries memory.
     * 
     * @param buffer
     *            buff
     */
    void free(IMemoryBuffer buffer);

}
